package com.qf.flash.ui.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.qf.flash.R;
import com.qf.flash.model.ScriptRoomBean;
import com.qf.flash.utils.ImageLoader;
import com.qf.flash.widget.RatingBarView;
import com.qf.flashlib.adapter.BaseRViewItem;
import com.qf.flashlib.adapter.RViewHolder;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * 2020/3/5 15:09
 */
public class ScriptItem extends BaseRViewItem<Object> {

    private Context mContext;
    public ScriptItem(Context mContext) {
        this.mContext = mContext;
    }


    @Override
    public boolean isItemView(Object entity, int position) {
        return entity instanceof ScriptRoomBean;
    }

    @Override
    public int getItemLayout() {
        return R.layout.item_script;
    }

    @Override
    public void convert(RViewHolder holder, Object bean, int position, int itemSize) {
        ScriptRoomBean entity = (ScriptRoomBean) bean;
        ImageView ivPic = holder.getView(R.id.iv_head);
        RatingBarView rbvStar = holder.getView(R.id.rbv_star);
        TagFlowLayout tflTag = holder.getView(R.id.tfl_tag);
        rbvStar.setStar(Math.round(entity.getResponseScole()), false);
        ImageLoader.loadRoundCorners(mContext, entity.getImage(),ivPic, 5);
        holder
                .setText(R.id.tv_theme, entity.getTypeName())
                .setText(R.id.tv_name,  entity.getName() )
                .setText(R.id.tv_score, entity.getResponseScole() + "分")
                .setText(R.id.tv_total_comment, entity.getResponseCount() + "次评论");
        initTag(mContext, tflTag, entity.getTags());
    }


    private void initTag(Context context, TagFlowLayout tflTag, List<String> tags) {
        tflTag.setAdapter(new TagAdapter<String>(tags) {
            @Override
            public View getView(FlowLayout parent, int position, String s) {
                TextView tv_hot = (TextView) LayoutInflater.from(context).inflate(R.layout.item_tag, tflTag, false);
                tv_hot.setText(s);
                return tv_hot;
            }
        });

    }
}
